package com.efast.dmom.mes.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.PartInventory;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.PartInventoryEntity;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.PartInventoryService;

@Controller
@RequestMapping("/inventory")
class PartInventoryController {
	
	@Autowired
	private PartInventoryService partInventoryService;
	
	@RequestMapping(value = "/operateByPartInventory")
	public @ResponseBody ResultBean operateByPartInventory(@RequestBody PartInventory partInventory) {
		
		PartInventoryEntity entity = partInventory.getInnerData();
		
		// Determine the new
		if ( partInventory.getModificationFlag() == IModificationFlags.NEW) {
			return partInventoryService.save(partInventory);
			// Judge update
		} else if (partInventory.getModificationFlag() == IModificationFlags.MODIFIED) {
			return partInventoryService.update(partInventory);
			// Judge to delete
		} else if (partInventory.getModificationFlag() == IModificationFlags.DELETED) {
			return partInventoryService.delete(partInventory);
		}
		return null;
	}

}
